package com.tcd.web.controller;


import com.tcd.pojo.User;
import com.tcd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author space
 * @since 2021-05-21
 */
@RestController
@RequestMapping("/permission/user")
@CrossOrigin
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("doLogin")
    public User doLogin(String account, String password){
        return userService.getUserByAccountAndPassword(account,password);
    }

    @RequestMapping("getUsers")
    public List<User> getUserFilter(@RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String userName, Integer roleId){
        return userService.getUserFilter(pageIndex,pageSize,userName,roleId);
    }

    @RequestMapping("getUsersCount")
    public Integer getUserFilterCount(String userName, Integer roleId){
        return userService.getUserFilterCount(userName,roleId);
    }

    @RequestMapping("addUser")
    public Integer addUser(@RequestBody User user){
        return userService.addUser(user);
    }

    @RequestMapping("updateUser")
    public Integer updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    @RequestMapping("deleteUser")
    public Integer deleteUsers(Integer[] ids){
        return userService.deleteUsers(ids);
    }

    @RequestMapping("setUserRoles")
    public Integer setUserRoles(@RequestParam(required = true) Integer uid, Integer[] roleIds){
        return userService.setUserRoles(uid,roleIds);
    }

    @RequestMapping("getUserByGroup")
    public List<User> getUserByGroup(Integer groupId) {
        return userService.getUserByGroup(groupId);
    }
}

